<?php

namespace app\common\service\finance\FinanceScene;

use app\common\service\finance\FinanceManager;
use app\model\CouponOrder;
use app\task\cron\coupon\SettleOrder;

/**
 * 目前没有在实际场景用到，测试用到了，如果需要用到可以直接转正 加上判断状态
 */
class SettleOrderAddProfit extends FinanceSceneBase
{

    protected $couponOrder;

    public function __construct(CouponOrder $couponOrder)
    {
        $this->couponOrder = $couponOrder;
    }


    public function handle(): bool
    {

        if ($this->couponOrder->agent_settle_status != CouponOrder::C_AGENT_SETTLE_STATUS_WAIT) {
            return false;
        }


        return true;
    }

    public function moneyChange(): string
    {
        return FinanceManager::TYPE_INC;
    }

    public function agentId(): int
    {
        return $this->couponOrder->agent_id;
    }

    public function amount(): int
    {
        return $this->couponOrder->profit;
    }

    public function type(): int
    {

        $trsType = (new SettleOrder(app(), cache()))->trsType;

        return $trsType[$this->couponOrder->serv_type] ?? BALANCE_COUPON_COMMISS;
    }

    public function balanceType(): int
    {
        return FinanceManager::BALANCE_PROFIT;
    }

    public function quoteId()
    {
        return $this->couponOrder->id;
    }

    public function remark()
    {
        return '佣金结算订单id：' . $this->couponOrder->order_id;
    }
}